<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/pages/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="Generator" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>鹰牌陶瓷合肥运营中心</title>
<style type="text/css">
body{height:100%;margin:0px;padding:0px}
#container{width:60%;height:60%}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
</head>
<body>
<div id="container" style="width:700px;height:500px;"></div>
<script type="text/javascript">
	var map = new BMap.Map("container");          // 创建地图实例
	var point = new BMap.Point(117.290657,31.812237);  // 创建点坐标
    map.centerAndZoom(point, 17);                 // 初始化地图，设置中心点坐标和地图级别
    map.addControl(new BMap.NavigationControl());  
    map.addControl(new BMap.OverviewMapControl());  

	function focusGrid(grid){
		//添加红色标注
		var point = new BMap.Point(grid.longitude,grid.latitude);
		var marker = new BMap.Marker(point);
		map.addOverlay(marker);

		map.setCenter(point);//设置地图中心

		marker.addEventListener("click", function(){ 
		   var infoWindow = getInfoWindow(grid);
		   this.openInfoWindow(infoWindow);
		   //图片加载完毕重绘infowindow
		   //document.getElementById('imgDemo').onload = function (){
		   //   infoWindow.redraw();
		   //};
		});

		marker.openInfoWindow(getInfoWindow(grid));
	}

	function getInfoWindow(grid){
		var img = "";
		if(grid.imgurl != "" && grid.imgurl != null){
			img = "<img style='float:right;margin:4px' id='imgDemo' src='${ctx}/"+ grid.imgurl +"' width='139' height='104' title='"+ grid.gridname +"'/>";
		}
		var sContent = "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>" + grid.gridname + "</h4>" + img +
		"<p style='margin:0;line-height:1.5;font-size:13px;width:360px'><b>地址</b>：" + grid.gridaddr + "</p>" + 
		"<p style='margin:0;line-height:1.5;font-size:13px;'><b>电话</b>：" + grid.gridtel + "</p>" + 
		"</div>";  
		var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象  
		return infoWindow;
	}

	window.onload = function (){
		var office_id = '<%=request.getParameter("office_id")%>';
		var longitude = parent.document.getElementById("longitude_" + office_id).value;
		var latitude = parent.document.getElementById("latitude_" + office_id).value;
		var gridname = parent.document.getElementById("gridname_" + office_id).value;
		var gridaddr = parent.document.getElementById("gridaddr_" + office_id).value;
		var gridtel = parent.document.getElementById("gridtel_" + office_id).value;
		var imgurl = parent.document.getElementById("imgurl_" + office_id).value;
		var grid = {'longitude':longitude,"latitude":latitude,"gridname":gridname,"gridaddr":gridaddr,"gridtel":gridtel,"imgurl":imgurl};
		focusGrid(grid);
	};
</script>
</body>
</html>
